|
|
 |
|
|
|
|
7: Public Sub clickedUndoBtn()
8: theBusiness.setMemento theBusinessMemento
9: theForm.Text1 = theBusiness.MyName
10: End Sub |
|
|
|
|
|
|
|
|
The object, theBusinessMemento, is a property of FormController created using Class Builder. Class Builder takes care of the details of creating properties by automatically inserting the get, let, and, if necessary, set statements and the modular declaration of the private object variable. That private declaration is |
|
|
|
|
|
|
|
|
Private mvartheBusinessMemento As BusinessMemento |
|
|
|
|
|
|
|
|
The class BusinessMemento represents a Memento object for a hypothetical business class named Business. The createMemento method of theBusiness creates a BusinessMemento object that holds the state of theBusiness using a private array of values. Each of these array items represents the values of each property of theBusiness. The Business class will be discussed shortly. The form object, called theForm, represents the privately declared reference to the sample form, frmTest. For the sake of convenience, it is probably advisable to design your form controllers to actually own a reference to the form it controls. For typical startup forms, use Sub Main to invoke a method to display the form, as follows: |
|
|
|
|
|
|
|
|
Public Sub Main()
theFormController.showForm
End Sub |
|
|
|
|
|
|
|
|
The showForm method looks like Listing 11.5. Here, the MyName property of theBusiness object is initialized to the name of the author. The object, theForm, is then initialized to the actual form, the Text1 control on the form is initialized to the MyName property of theBusiness, and then the form is displayed. |
|
|
|
|
|
|
|
|
LISTING 11.5. THEshowFormMETHOD OFtheFormController. |
|
|
|
 |
|
|
|
|
1: Public Sub showForm()
2: theBusiness.MyName = "John Conley"
3: Set theForm = New frmTest
4:
5: theForm.Text1 = theBusiness.MyName
6: theForm.Show
7: End Sub |
|
|
|
|
|